package com.cloudfun.campusshare.repo;

import com.cloudfun.campusshare.common.constant.ApplicationStatus;
import com.cloudfun.campusshare.common.constant.ApplicationType;
import com.cloudfun.campusshare.entity.ApplicationEntity;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.Collection;
import java.util.List;

/**
 * Created by Huqin on 2019/12/30
 */
public interface ApplicationEntityRepo extends
        PagingAndSortingRepository<ApplicationEntity, String>,
        JpaSpecificationExecutor<ApplicationEntity> {

    ApplicationEntity findByIdAndAuditorId(String id, String auditorId);

    List<ApplicationEntity> findAllByBizId(String bizId);

    ApplicationEntity findByIdAndEnabled(String id, Boolean enabled);

    ApplicationEntity findByBizIdAndTypeAndEnabled(String bizId, ApplicationType applicationType, Boolean enabled);

    ApplicationEntity findTopByBizIdAndTypeAndEnabledOrderByCreateTimeDesc(String bizId, ApplicationType applicationType, Boolean enabled);

    List<ApplicationEntity> findAllByIdInAndEnabled(Collection<String> ids, Boolean enabled);

    Long countByTypeNotInAndStatusAndEnabled(Collection<ApplicationType> types, ApplicationStatus status, Boolean enabled);
}
